package com.weetop.akly.presenter;

import android.app.Activity;

import com.weetop.akly.base.mvp.BaseModel;
import com.weetop.akly.base.mvp.BaseObserver;
import com.weetop.akly.base.mvp.BasePresenter;
import com.weetop.akly.bean.VoteBean;
import com.weetop.akly.bean.VoteItem;
import com.weetop.akly.view.VoteDetailView;

import java.util.ArrayList;
import java.util.Map;

public class VoteDetailPresent extends BasePresenter<VoteDetailView> {
    public VoteDetailPresent(VoteDetailView baseView, Activity activity) {
        super(baseView, activity);
    }

    /**
     * 获取投票信息
     */
    public void getVoteInfo(int id) {
        if (id == -1) {
            return;
        }
        addDisposable(apiServer.getVoteInfo(id + ""), new BaseObserver<BaseModel<VoteBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<VoteBean> o) {
                baseView.getVoteInfoSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    /**
     * 投票
     */
    public void doVote(int id, int status) {
        if (id == -1) {
            return;
        }
        addDisposable(apiServer.doVote(id + "", status + ""), new BaseObserver<BaseModel<Boolean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<Boolean> o) {
                baseView.doVoteSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

}
